<#include "/WEB-INF/views/admin/common/layout/__mainlayout.html">
<#include "/WEB-INF/views/admin/common/__pagination.html">
<#assign navLink='admin:sys:role:list' />
<#assign pageCss>
<link rel="stylesheet" href="${ctx}/resource/validationengine/css/validationEngine.jquery.css">
</#assign>
<#assign pageScript>
<script type="text/javascript" src="${ctx}/resource/validationengine/js/jquery.validationEngine-zh_CN.js"></script>
<script type="text/javascript" src="${ctx}/resource/validationengine/js/jquery.validationEngine.js"></script>
<script type="text/javascript">
$(document).ready(function() {
	$("#addBtn").click(function(){
		layer.open({
			title:'add role',
		    type: 2,
		    area: ['800px', '600px'],
		    scrollbar: false,
		    content: '${ctx}/admin/sys/role/add_edit',
		    end : function() {
				window.location.reload();
			}
		});
	});
});

function grant(id){
	layer.open({
		title:'allocate resources',
	    type: 2,
	    area: ['580px', '530px'],
	    fix: false, //不固定
	    content: '${ctx}/admin/sys/role/grant?roleId='+id+'&type=1'
	});
}

function editRole(id){
	layer.open({
		title:'edit role',
	    type: 2,
	    area: ['800px', '600px'],
	    scrollbar: false,
	    content: '${ctx}/admin/sys/role/add_edit?id=' + id,
	    end : function() {
			window.location.reload();
		}
	});
}
function deleteRole(id) {
	layer.confirm('do you decide to delete it？', {
	    btn: ['yes','no'], //按钮
	}, function(index){
		$.ajax({
			type : "POST",
			url : "${ctx}/admin/sys/role/delete",
			data : {
				"id" : id
			},
			success : function(result) {
				if (result.isSuccess) {
					layer.msg(result.msg, {
						icon : 1,
						time : 500,
						end : function() {
							window.location.reload();
						}
					});
				} else {
					layer.msg(result.msg, {
						time : 500,
						icon : 2
					});
				}

			}
		});
	    // 提交表单的代码，需要你自己写，然后用 layer.close 关闭就可以了，取消可以省略
	    layer.close(index);
	});
	
	
	
}
</script>
</#assign>
<@mainlayout>
<div class="row-content am-cf">
	<div class="row">
		<div class="am-u-sm-12 am-u-md-12 am-u-lg-12">
			<div class="widget am-cf">
				<div class="widget-head am-cf">
					<div class="widget-title  am-cf">role list</div>
				</div>
				<div class="widget-body  am-fr">
					<div class="am-u-sm-12 am-u-md-6 am-u-lg-6">
						<div class="am-form-group">
							<div class="am-btn-toolbar">
								<div class="am-btn-group am-btn-group-xs">
								<@hasperm key='admin:sys:role:save'>
									<button type="button" class="am-btn am-btn-default am-btn-success" id="addBtn">
										<span class="am-icon-plus"></span> add
									</button>
								</@hasperm>
								</div>
							</div>
						</div>
					</div>
					<form action="${ctx}/admin/sys/role/list/" method="post">
						<div class="am-u-sm-12 am-u-md-12 am-u-lg-3 am-fr">
							<div class="am-input-group am-input-group-sm tpl-form-border-form cl-p">
								<input type="text" class="am-form-field " name="search" value="${search}" placeholder="please enter the name to search"> 
									<span class="am-input-group-btn">
									<button
										class="am-btn  am-btn-default am-btn-success tpl-table-list-field am-icon-search"
										type="submit">
									</button>
								</span>
							</div>
						</div>
					</form>
					<div class="am-u-sm-12 am-scrollable-horizontal">
	                  <table width="100%" class="am-table am-table-compact tpl-table-black am-text-nowrap am-table-hover " id="example-r">
	                      <thead>
	                          <tr>
	                              <th class="am-u-sm-1 am-text-truncate">ID</th>
	                              <th class="am-u-sm-2 am-text-truncate">name</th>
	                              <th class="am-u-sm-2 am-text-truncate">description</th>
	                              <th class="am-u-sm-1 am-text-truncate">sort</th>
	                              <th class="am-u-sm-2 am-text-truncate">update_time</th>
	                              <th class="am-u-sm-2 am-text-truncate">status</th>
	                              <th class="am-u-sm-2 am-text-truncate">operation</th>
	                          </tr>
	                      </thead>
	                      <tbody>
	                      	<#list pageList.list as role>
	                          <tr class="gradeX">
	                              <td class="am-u-sm-1 am-text-truncate">${role.id!}</td>
	                              <td class="am-u-sm-2 am-text-truncate">${role.name!}</td>
	                              <td class="am-u-sm-2 am-text-truncate">${role.des!}</td>
	                              <td class="am-u-sm-1 am-text-truncate">${role.seq!}</td>
	                              <td class="am-u-sm-2 am-text-truncate">${role.createdate!}</td>
	                              <td class="am-u-sm-1 am-text-truncate">
	                              	<#if role.status == 1><font class="am-text-success">published</font>
	                              	<#else><font class="am-text-danger">suspend</font>
	                              	</#if>
	                              </td>
	                              <td class="am-u-sm-3 am-text-truncate">
	                                  <div class="tpl-table-black-operation">
	                                  <@hasperm key='admin:sys:res:save'>
	                                      <a href="javascript:editRole('${role.id}');">
	                                          <i class="am-icon-pencil"></i> edit
	                                      </a>
	                                  </@hasperm>
	                                  <@hasperm key='admin:sys:res:delete'>
	                                      <a href="javascript:deleteRole('${role.id}');" class="tpl-table-black-operation-del">
	                                          <i class="am-icon-trash"></i> delete
	                                      </a>
	                                  </@hasperm>
	                                  <@hasperm key='admin:sys:res:save'>
	                                      <a href="javascript:grant('${role.id}');">
	                                          <i class="am-icon-edit"></i> allocate
	                                      </a>
	                                  </@hasperm>
	                                  </div>
	                              </td>
	                          </tr>
	                          </#list>
	                          <!-- more data -->
	                      </tbody>
	                  </table>
	              </div>
              	  <@pagination page=pageList url='/admin/sys/role/list?' />
              </div>
			</div>
		</div>
	</div>
</div>
</@mainlayout>

